﻿using StarPizza.Model.BaseModel;
using StarPizza.ViewModel.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarPizza.ViewModel.ClientSystem
{
    class CustomPizzaOrderer : PizzaOrderer
    {
        PizzaComposer pizzaComposer;
        public PizzaComposer PizzaComposer { get { return pizzaComposer; } }

        public CustomPizzaOrderer(PizzaComposer pizzaComposer, OrderController orderController, DoughLister doughLister)
            : base(orderController, doughLister)
        {
            this.pizzaComposer = pizzaComposer;
            pizzaComposer.ToppingsChanged += pizzaComposer_ToppingsChanged;
            doughLister.IngredientVMSelected += doughLister_DoughVMSelected;
        }

        void doughLister_DoughVMSelected(DoughVM dough)
        {
            OnPropertyChanged("PizzaPrice");
        }
        void pizzaComposer_ToppingsChanged()
        {
            OnPropertyChanged("PizzaPrice");
        }
        public int PizzaPrice
        {
            get 
            {
                int doughPrice = 0;
                if (SelectedDoughVM != null)
                    doughPrice = SelectedDoughVM.Price;
                return doughPrice + pizzaComposer.SumToppingPrice; 
            }
        }
        public void FinishedPizza()
        {
            var toppings = pizzaComposer.ChosenToppingVMs.ToList().ConvertAll(
                toppingVM => toppingVM.WrappedTopping);
            OrderPizza(new CustomPizzaTemplate(toppings,"Saját"));
            pizzaComposer.ClearChosenToppingVMs();
        }
    }
}
